get the outgoing link path and paste it in a new attribute

Hi,

I am a new bee for DOORS.

I have a module in which outgoing links are given to all objects(Under an attribute "new text"). Now i want to copy the address/path of the outgoing links of each object and put it in a new attribute called "link path". I am really confused where to start this with dxl script.

Do we have any inbuilt script to get the link path? Any idea or script would help me a lot.

thanks.

Ashok
AshokNandha - Thu Feb 23 05:48:02 EST 2012

Re: get the outgoing link path and paste it in a new attribute
ashokanumula - Thu Feb 23 07:50:03 EST 2012

Hope following script works.

Object o
Link l
Module m = current
ModName_ mod
string s

for o in m do
{
for l in o ->"*" do
{
mod= target(l)
s= fullName(mod)
o."link path""" = s
}
}

Re: get the outgoing link path and paste it in a new attribute
AshokNandha - Thu Feb 23 08:34:33 EST 2012

ashokanumula - Thu Feb 23 07:50:03 EST 2012
Hope following script works.

Object o
Link l
Module m = current
ModName_ mod
string s

for o in m do
{
for l in o ->"*" do
{
mod= target(l)
s= fullName(mod)
o."link path""" = s
}
}

Hi Ashok,

Thanks! I tried with the following script which is similar to yours, and its working.
(it picks the name and puts in a new attribute). One problem i face is, it picks only the last link path not all the path. i.e If the object has 3 links, this script copies only the third link path and pastes.
Any suggestion to sort it out?

Object o = null
LinkRef lref
ModName_ srcModRef
for o in current do
{
if(!null o)
{
for lref in o<-"*" do
{
srcModRef = source lref
o."link path" = fullName(srcModRef)
}
}
}

Thanks.

Re: get the outgoing link path and paste it in a new attribute
Lion29 - Thu Feb 23 09:57:09 EST 2012

AshokNandha - Thu Feb 23 08:34:33 EST 2012
Hi Ashok,

Thanks! I tried with the following script which is similar to yours, and its working.
(it picks the name and puts in a new attribute). One problem i face is, it picks only the last link path not all the path. i.e If the object has 3 links, this script copies only the third link path and pastes.
Any suggestion to sort it out?

Object o = null
LinkRef lref
ModName_ srcModRef
for o in current do
{
if(!null o)
{
for lref in o<-"*" do
{
srcModRef = source lref
o."link path" = fullName(srcModRef)
}
}
}

Thanks.

For this issue, you will have to put a dummy string variable and append the values for all the links in an object.
While looping for the next object, reset the dummy string variable. This should solve the problem.

Re: get the outgoing link path and paste it in a new attribute
AshokNandha - Thu Feb 23 12:00:57 EST 2012

Lion29 - Thu Feb 23 09:57:09 EST 2012
For this issue, you will have to put a dummy string variable and append the values for all the links in an object.
While looping for the next object, reset the dummy string variable. This should solve the problem.

Thanks. Solved!

Re: get the outgoing link path and paste it in a new attribute
llandale - Thu Feb 23 14:32:38 EST 2012

General

"Link" information is stored in the module sourcing the link. So you can always see outgoing links of an object. But you can only see incoming "Link"s when the other Source module is open. When DXL deals with incoming links you need to first make sure those other modules are open.'

In the DXL manual:

  • Chapter "Links"
  • Section "Finding links"
  • command "for all source references"

We see a simple script to pre-open those modules.

  • ModName_ srcModRef
  • for srcModRef in o<-"*" do read(fullName(srcModRef), false

Although I advise routinely opening the standard view of that module rather than the default view:

  • read(fullName(srcModRef), false, true)

The above code should be routine before dealing with incoming links:

  • ModName_ srcModRef
  • for srcModRef in o<-"*" do read(fullName(srcModRef), false, true)
  • Link lnk
  • for lnk in o<-"*" do
  • { We can now see the links

 

Specific

If you just want a list of every module that has links incoming to the current object and don't care which source objects they are nor how many there are, then you really don't need to pre-open those modules since you don't actually need to look at the "Link" and the name is already available.
A "Skip" list works pretty well as it allows you to insert the same name and it will ignore the duplicates.
A "Buffer" is the structure of choice when manipulating strings.

 

 

ModName_ srcModRef 
Skip skpSources = createString()   // KEY and DATA both 'string' name of source module
Buffer bufSources = create()
for srcModRef in o<-"*" do 
{  put(skpSources, fullName(srcModRef), fullName(srcModRef))
}
string SourceName
for SourceName in skpSources do
{  if (length(bufSources) != 0) bufSources += "\n"  // EOL after previous Name
   bufSources += SourceName
}
o."LinkPath" = bufSources
delete(bufSources)
delete(skpSources)


If you want to remember how many links from each module or more likely want to record the Identifier of each objects sourcing a link, you will need to open that source module.

-Louie

String concatenation within a loop is a disaster:

 

 

  • string Results = ""; int i
  • for (i=0; i<1000; i++) Results = Results "A"

Results is 1000 "A"s but wasted memory space explodes I think in this case 500,000 characters.
Thus use Buffers, where you just append to the end using "+=".

 

Re: get the outgoing link path and paste it in a new attribute
AshokNandha - Fri Feb 24 10:43:20 EST 2012

llandale - Thu Feb 23 14:32:38 EST 2012

General

"Link" information is stored in the module sourcing the link. So you can always see outgoing links of an object. But you can only see incoming "Link"s when the other Source module is open. When DXL deals with incoming links you need to first make sure those other modules are open.'

In the DXL manual:

  • Chapter "Links"
  • Section "Finding links"
  • command "for all source references"

We see a simple script to pre-open those modules.

  • ModName_ srcModRef
  • for srcModRef in o<-"*" do read(fullName(srcModRef), false

Although I advise routinely opening the standard view of that module rather than the default view:

  • read(fullName(srcModRef), false, true)

The above code should be routine before dealing with incoming links:

  • ModName_ srcModRef
  • for srcModRef in o<-"*" do read(fullName(srcModRef), false, true)
  • Link lnk
  • for lnk in o<-"*" do
  • { We can now see the links

 

Specific

If you just want a list of every module that has links incoming to the current object and don't care which source objects they are nor how many there are, then you really don't need to pre-open those modules since you don't actually need to look at the "Link" and the name is already available.
A "Skip" list works pretty well as it allows you to insert the same name and it will ignore the duplicates.
A "Buffer" is the structure of choice when manipulating strings.

 

 

ModName_ srcModRef 
Skip skpSources = createString()   // KEY and DATA both 'string' name of source module
Buffer bufSources = create()
for srcModRef in o<-"*" do 
{  put(skpSources, fullName(srcModRef), fullName(srcModRef))
}
string SourceName
for SourceName in skpSources do
{  if (length(bufSources) != 0) bufSources += "\n"  // EOL after previous Name
   bufSources += SourceName
}
o."LinkPath" = bufSources
delete(bufSources)
delete(skpSources)


If you want to remember how many links from each module or more likely want to record the Identifier of each objects sourcing a link, you will need to open that source module.

-Louie

String concatenation within a loop is a disaster:

 

 

  • string Results = ""; int i
  • for (i=0; i<1000; i++) Results = Results "A"

Results is 1000 "A"s but wasted memory space explodes I think in this case 500,000 characters.
Thus use Buffers, where you just append to the end using "+=".

 

Thanks a lot for the explanation. I tested the above code. Its working fine. I tried to put for loop to traverse through all the object which ever is having link. But its throwing error. Currently it updates the object if that is selected.

Re: get the outgoing link path and paste it in a new attribute
AshokNandha - Fri Feb 24 11:06:01 EST 2012

AshokNandha - Fri Feb 24 10:43:20 EST 2012
Thanks a lot for the explanation. I tested the above code. Its working fine. I tried to put for loop to traverse through all the object which ever is having link. But its throwing error. Currently it updates the object if that is selected.

Thanks I am able to run it now.

Object o = current
ModName_ srcModRef
for o in current do
{
Skip skpSources = createString() // KEY and DATA both 'string' name of source module
Buffer bufSources = create()

for srcModRef in o<-"*" do
{ put(skpSources, name(srcModRef), name(srcModRef))
}
string SourceName
for SourceName in skpSources do
{ if (length(bufSources) != 0) bufSources += ", \n" // EOL after previous Name
bufSources += SourceName
}
o."link" = bufSources
delete(bufSources)
delete(skpSources)
}
Thanks again for the explanation.

Re: get the outgoing link path and paste it in a new attribute
llandale - Fri Feb 24 12:09:13 EST 2012

AshokNandha - Fri Feb 24 11:06:01 EST 2012
Thanks I am able to run it now.

Object o = current
ModName_ srcModRef
for o in current do
{
Skip skpSources = createString() // KEY and DATA both 'string' name of source module
Buffer bufSources = create()

for srcModRef in o<-"*" do
{ put(skpSources, name(srcModRef), name(srcModRef))
}
string SourceName
for SourceName in skpSources do
{ if (length(bufSources) != 0) bufSources += ", \n" // EOL after previous Name
bufSources += SourceName
}
o."link" = bufSources
delete(bufSources)
delete(skpSources)
}
Thanks again for the explanation.

You don't need to set "o" to current. You do need to be mindful of which "Module" is current as sometimes it changes unpredicably. Perhaps use these as the first few lines:

Object o
ModName_ srcModRef 
Module mod = current
print "Setting source references for module: '" name(mod) "'...\n"
for o in mod do


Understand the "for o in mod do" loop puts your code at the mercy of the current filtering etc, as that loop only sees objects currently displayed. I have a minority opinion that this is better:

 

for o in entire mod do
{  if (isDeleted(o))     continue
   if (for some other reason I want to ignore o) continue
   proceed to deal with o
}


-Louie